package com.supermate.supercut.domain.model;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import lombok.Data;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Author: 冰岩
 * @Date: 2023/10/28
 * @Description:
 */
@Data
public class FileResource extends DefaultExpandable {

    public static final String PREVIEW_IMG_KEY = "preViewImgs";

    Long id;

    String fileName;

    String clipboardName;

    Date uploadTime;

    Date gmtModify;

    /** 下载次数 */
    Long downLoadTimes;

    /** 相对路径 */
    String relativePath;

    /** 获取预览图片 */
    public List<String> getPreviewImgs() {
        String imgsJson = getExtAttrDefault(PREVIEW_IMG_KEY);
        if (Objects.isNull(imgsJson)) {
            return Collections.emptyList();
        }
        return JSON.parseObject(imgsJson, new TypeReference<List<String>>(){});
    }

}
